package com.gonsin.gview.logic.services.data;

import com.gonsin.gview.annotations.GContext;
import com.gonsin.gview.annotations.interfaces.IListDataPicker;
import com.gonsin.gview.logic.model.DataRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 列表数据处理器
 */
public class GListDataPickerManager extends GDataManager{

    private GContext context;

    private String dataId;

    private IListDataPicker picker;

    public GListDataPickerManager(GContext context, String dataId, IListDataPicker picker) {
        super(GListDataPickerManager.class.getName(), picker.getClass().getName());
        this.context = context;
        this.dataId = dataId;
        this.picker = picker;
    }

    @Override
    public Object generalData(HttpServletRequest request, HttpServletResponse response, DataRequest dataRequest) {
        Map<String, Object> props = dataRequest.getProps();
        if(dataRequest.getProps() == null){
            props = new HashMap<>();
        }
//        List<KeyValue> kvs = dataRequest.getProps();
//        if(!CollectionUtils.isEmpty(kvs)){
//            kvs.forEach(kv -> {
//                props.put(kv.getKey(), kv.getValue());
//            });
//        }
        return picker.getData(context, dataId, request, props);
    }
}
